Repository navigation
Add netcdf output of the hemispheric diagnostics (area, extent, etc) - #1145
anton-seaice wants to merge 21 commits into
Conversation
|
@apcraig @eclare108213 @dabail10 Just putting this up for discussion
|
|
Please update your branch to the Consortium trunk to get the updated Github Actions workflow script. You can merge or rebase, both should work just as well. |
eclare108213
left a comment
There was a problem hiding this comment.
This looks like a very useful upgrade. My only comment at this point is that whatever is done (or not) for history restarts should be the same for netcdf diagnostics.
|
This looks very nice. A few thoughts
|
|
My comments are similar to @apcraig.
|
|
Thanks for the comments all !
Yep - can do this. Should it go in a seperate restart file or the history restart file ?
Do you mean The log includes diagnostics which are always on (area, extent, volume) and extra's turned on through
For reasons I don't 100% recall it seemed simpler not to change the log output. So yes, log output is instantaneous it's not that clear to me that time averaging some of the variables in the log would be useful if averaged. e.g.
the
Actually it's accumulating the spatial fields and then summing at the diagnostic frequency. Global sum should be being done at the diagnostic frequency, not every thermo/coupling timestep. Cost is nominal.
On our hardware, there's no performance improvement in doing this is small (at least for the netcdf diagnostics).
Possibly, but it quickly leads to not progressing this change - and instead adding 1d variables as history fields (which in my view needs more history streams) The accumulation code is very small : The other overlap is in the netcdf file definition ? Which could overlap a bit with history files p.s. did you mean code reuse between the log and history diagnostic implementation ? or code reuse between the log and netcdf diagnostic implementation ?
The global sum is only done at the diagnostic frequency. The cost is small (and off by default).
yep, this is an option. In my view it needs more history streams which bring different complications. My medium term goal here is configuring one 3d/4d variable per history file, whilst keeping the 2d (hemsiphere & time) variables in a single file. So ice_diag fills the second goal (the 2d variables in a single file)
yep, should be fine. ill work on this soon. Are you thinking of one file per run? or the same file over consecutive model runs ? |
The current implementation has each history file with it's own restart history file. I would keep that standard.
I'm asking about "diagfreq". This seems to control the frequency of output to the log file AND to the netcdf file. These seem like distinct features that probably require distinct frequency control mechanisms. So yes, you might want different frequencies for log and netcdf output.
Good, that should work well.
Great.
I was concerned that the log diagnostics and 1D history diagnostics were computed using duplicate code. If the code that computes the global sums could be shared between the log and 1D history output to ensure "ice area", "ice volume", and other diagnostic would always be guaranteed to be exactly the same, I think that would be very useful.
I think the history diagnostics are different enough that they deserve their own history file. The history streams are largely model output fields possibly aggregated in time. The history diagnostics are model fields aggregated possibly in time and always in space (by hemisphere). These new files sort of break our standard x,y,z,n,t history mechanism and require another step (aggregating in space). I like the simplicity of just turning the feature on or off and not having to manage which fields go into the history diagnostics file. Having said that, maybe the 1d history diagnostic netcdf output should be part of the history mechanism in the sense that we should be able to add 1 more stream for it, all the temporal aggregation, time axis stuff, and history restart features are there. And we would just have to add the global sums and ability to write 1D by hemisphere output.
I think that's a separate feature, although it clearly overlaps with the history diagnostics. If the history diagnostics are going to support multiple time slices per file, how is that going to be managed? |
- diagfreq_unit ('1','h','d','m','y') sets the units of diagfreq, default '1'
(timesteps) is unchanged. Calendar units are aligned with the calendar,
e.g. 'd' writes at the end of each day and 'm' at the end of each month.
- write_diag is computed once in calendar and used by all drivers, replacing
mod(istep,diagfreq) in each driver.
- diag_netcdf writes the hemispheric diagnostics from the log (and the
print_global set) to a netcdf file, one file per run named
<history_file>_diag.<run start date>.nc, as instantaneous values with
_nh/_sh variables.
- Add set_nml.diagnc and a base_suite test, update docs.
Addresses CICE-Consortium#1074
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… compliance Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…cs file cdf2/cdf5 (and pnetcdf2/5) use 64-bit offset/data, hdf5 uses netcdf4 with history_deflate compression, otherwise classic. The file is always written serially on the master task. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Move the netcdf diagnostics to ice_diagnostics_netcdf.F90, called from the drivers with diag_netcdf_step, so runtime_diags is unchanged apart from the kinetic energy and ice speed helpers it now shares. - diag_netcdf_avg (default true) writes time averages over each diagfreq interval, accumulated every timestep from per grid cell values, with one global reduction per record. Maxima are maxima over the interval. - Each diagnostic is defined once (init_ncdiag) and computed per grid cell (ncdiag_cell_values), and used for both averages and instantaneous values. - CMIP names and units for sea-ice area, extent, volume and snow mass. - One file per mode (<history_file>_diag_mean.nc or _diag_inst.nc), appended to at the start of a run, with records from a rerun overwritten. - Precision follows history_precision, time_bounds and cell_methods for means, missing values for a hemisphere without grid cells. - print_global diagnostics are only written to the log. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Rename the hemisphere loop index nh to hemi. - Add units_metadata = "leap_seconds: none" to time for proleptic_gregorian. - Use half a timestep as the tolerance when finding records to overwrite. - Clarify comments and document that averages restart at the start of a run. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Replace the diag_netcdf and diag_netcdf_avg logicals with one string, so there are no meaningless combinations, matching hist_avg and the planned hist_mode. Files are <history_file>_diag_avg.nc or _diag_inst.nc. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- diag_netcdf_freq and diag_netcdf_freq_n set the netcdf diagnostics frequency
('x' off), separate from the log diagnostics (diagfreq, diagfreq_unit), with
a shared calendar helper.
- diag_netcdf_avg (like hist_avg) replaces diag_netcdf.
- With write_histrest, the accumulation for time averages is written to
<history_file>_diag_r.<date>.nc in restart_dir with the history restarts and
read at the start of the next run, so averages are continuous across restarts.
- Add set_nml.diagncr and a restart test with 3 day means.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Move the hemispheric diagnostic definitions, per grid cell values, reductions and derived values to ice_diagnostics (hdiag_*), used by runtime_diags and ice_diagnostics_netcdf, so the log and netcdf values are computed by the same code. The log output is unchanged. Snow is summed as volume, with rhos as the netcdf scale for sisnmass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Add the print_global per grid cell quantities (energy, salt, water, salt and heat fluxes, brine, ponds, isotopes, aerosols) to the shared hemispheric diagnostics when they are used, and derive the conservation budgets in hdiag_global, used by the log and netcdf. The log is unchanged. - With print_global, the netcdf file has masses, energy, salt and tracer totals, and fluxes as rates. The changes and conservation errors are over a single timestep, so are only written for instantaneous values. - Add a base_suite test with netcdf diagnostics every timestep. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nt_global only affects the log Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Previously no filename was set, so the previous stream's path was reused. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1dea0dc to
c8c51dc
Compare
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ments Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ctions Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The print_points diagnostics in ice_diagnostics and ice_diagnostics_bgc were broadcast from the owning task to all tasks, each followed by an MPI_BARRIER, although only the master task writes them. Add a generic send_to_master (dbl scalar, 1d and 2d) to ice_communicate and use it instead, so only the owning and master tasks communicate. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
This change is ready to go, it ended up being a bit bigger than hoped. I've harmonised the code between the log file and netcdf versions. base_suite results: all pass, and bit-for-bit with main (da68b70) for all tests with a baseline (the 3 new tests have none). |
apcraig
left a comment
There was a problem hiding this comment.
This looks great overall. A lot of good cleanup of code and looks like a robust implementation and excellent test coverage and documentation of the testing. I've added several comments inline about possible additional improvements and a couple questions.
| hd_aice = 1 , & ! sea-ice area | ||
| hd_extent = 2 , & ! sea-ice extent | ||
| hd_vice = 3 , & ! sea-ice volume | ||
| hd_vsno = 4 , & ! snow volume, netcdf snow mass |
| if (icepack_warnings_aborted()) call abort_ice(error_message=subname, & | ||
| file=__FILE__, line=__LINE__) | ||
|
|
||
| allocate(hdiag(n_hdiag_core + 16 + 4*n_iso + 4*n_aero)) |
There was a problem hiding this comment.
Document the number if indices here, where does that come from?
There was a problem hiding this comment.
thanks, I made these parameters
16 optional ones for the conservation budgets (hd_ptot to hd_frz in the module header);
4 per isotope and per aerosol tracer (flux from the atmosphere, flux to the ocean, total, maximum)
| diagfreq_unit = '1' ! units of diagfreq 'y', 'm', 'd', 'h', '1' | ||
| diag_netcdf_freq = 'x' ! netcdf hemispheric diagnostics frequency, 'x' off | ||
| diag_netcdf_freq_n = 1 ! netcdf hemispheric diagnostics frequency count | ||
| diag_netcdf_avg = .true. ! if true, netcdf diagnostics are time averages |
There was a problem hiding this comment.
wondering if diagfreq_netcdf, diagfreq_netcdf_n, diagavg_netcdf might be easier to read? Also, we need to make sure it's clear that log out is instantaneous at the frequency requested, while the netcdf output can be instantaneous or averaged.
Do we need a diagfreq_base like the history output for some phase control?
| !======================================================================= | ||
|
|
||
| ! Write hemispheric diagnostics to the netcdf diagnostics file, master task only. | ||
| ! There is one file for each of time averages and instantaneous values. It is |
There was a problem hiding this comment.
Change to "There is one file for all of the history diagnostics". I read it as one file per field as written.
|
|
||
| ! filename, _avg for time averages or _inst for instantaneous values, | ||
| ! as for history files | ||
| if (diag_netcdf_avg) then |
There was a problem hiding this comment.
OK, so there is one file per case or experiment. That makes sense. Will these files be OK if a run fails in the middle and the run is resubmitted and starts at the last restart file? Will the diagnostics and time axis be written/rewritten/overwritten correctly?
There was a problem hiding this comment.
There's a messy loop to overwrite when this happens:
There was a problem hiding this comment.
OK, so as I understand, this is handled gracefully. That loop opens the file and figures out the records that exist after the model time and then overwrites them. Thanks!
| if (n == 0) return | ||
|
|
||
| select case (unit) | ||
| case ("y", "Y") |
There was a problem hiding this comment.
There is some inconsistency in support for capital letter options "Y", "M", "D", etc. For the history/restart files, the freq option is not checked anywhere (from what I can see) and then "y" and "Y" are supported internally. I think if someone sets "a" for histfreq, it just won't do anything and it won't abort? For the new diagfreq option, the lower case options are checked in ice_init and aborted if not valid which means the upper case cannot be used and there is a clean check.
Can we make this more consistent and robust. A few options
- we only support lower case and they are all check in ice_init for valid values (like diagfreq is currently implemented). We clean up the implementation so capital letters are no longer valid internally.
- we support upper and lower case options for all freq settings, they are NOT checked in ice_init, but we add a "case default" option in ice_calendar or elsewhere where the model will abort if a freq setting is not valid.
- we support upper and lower case options, but upper case is converted to lower case in ice_init and then we follow step 1 above.
I think 3 works the best. Both upper and lower case are supported for all freq settings, we can remove the "upper case" implementation throughout the code, and each freq feature (hist, rest, diag) can have their own set of supported options checked in ice_init. We can also have a single general ice_calendar method to compute the "freq_now" value that doesn't need to worry whether "g" or "n" are valid values for one or another freq feature because those will be checked in ice_init. This should be backwards compatible and improve robustness and consistency. Does that sound like something that could be done in this PR? Happy to help with any of this.
| @@ -0,0 +1,3 @@ | |||
| diagfreq = 1 | |||
| diagfreq_unit = 'd' | |||
| diag_netcdf_freq = 'd' | |||
There was a problem hiding this comment.
Suggest diag_netcdf_freq_n is set explicitly as well.
| @@ -0,0 +1,2 @@ | |||
| diag_netcdf_freq = '1' | |||
There was a problem hiding this comment.
Suggest diag_netcdf_freq_n be set explicitly as well.
| @@ -0,0 +1,4 @@ | |||
| diagfreq = 12 | |||
There was a problem hiding this comment.
Suggest diagfreq_unit be set explicitly as well.
| dump_last = .false. | ||
| bfbflag = 'off' | ||
| diagfreq = 24 | ||
| diagfreq_unit = '1' |
There was a problem hiding this comment.
I'm wondering if we should clean up the namelist names now. We have diagfreq_unit/diagfreq and npt_unit/npt. Then we have dumpfreq/dumpfreq_n/dumpfreq_base, histfreq/histfreq_n/histfreq_base, and now diag_netcdf_freq/diag_netcdf_freq_n.
Some of this is due to the history of the namelist names and support for backwards compatibility. I think now might be a good time to make this more consistent and provide backwards compatibility (for now). There are a bunch of challenges with cleaning this up. I suggest we use histfreq_unit/histfreq_n/histfreq_base as the standard naming convention. So that would mean we would have to rename the following variables
diagfreq -> diagfreq_n
npt -> npt_n
dumpfreq -> dumpfreq_unit
histfreq -> histfreq_unit
diag_netcdf_freq -> diag_netcdf_freq_unit
We could continue to allow the old namelist for the time being and have ice_init copy the value into the new namelist name and write a warning message about use of a deprecated namelist name. We could also check that the old and new are both not set in the namelist. Documentation would be updated to reflect only the new namelist variable names.
As part of this, maybe we should use something other than "npt". Maybe "runlen" so runlen_unit/runlen_n? And I'll again promote diagfreq_netcdf_unit and diagfreq_netcdf_n or maybe even diaghistfreq_unit and diaghistfreq_n? So that would mean
diagfreq -> diagfreq_n
npt_unit -> runlen_unit
npt -> runlen_n
dumpfreq -> dumpfreq_unit
histfreq -> histfreq_unit
diag_netcdf_freq -> diaghistfreq_unit
diag_netcdf_freq_n -> diaghistfreq_n
And maybe add _base as needed for the options that need an _base that don't have it yet. We should verify I haven't missed any. Again, more than happy to discuss whether we should take this step (now would be a good time to do it), what nomenclature we should establish, and I'm happy to help with the implementation.
|
I will run some tests on derecho with multiple compilers once we feel this is close to being in final review. |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
I made an issue about the namelist: |
|
@anton-seaice, what's the status of this PR. Are you waiting for discussion of #1164? Do you want to defer that issue? There were a few other suggested changes to get this ready for testing and merge. No rush, just checking in. |
|
Yeah I think it's best to agree on the namelist names first, so we don't end up needed to change them again ? |
| if (print_global) then | ||
| ! conservation diagnostics, the same as the netcdf diagnostics | ||
| call hdiag_global(hdiag_n, 1, dt, budget_n) | ||
| call hdiag_global(hdiag_s, 2, dt, budget_s) |
There was a problem hiding this comment.
I like what you've done here
|
|
||
| character (len=*), intent(in) :: & | ||
| vname_n , & ! netcdf variable name, northern hemisphere | ||
| vname_s , & ! netcdf variable name, southern hemisphere |
There was a problem hiding this comment.
Are these attributes only used for the netcdf output? If so, could this routine be put in that module? Or is it here due to a circular dependency?
| ! Values to be summed are per unit area; they are multiplied by the cell | ||
| ! area when reduced. | ||
|
|
||
| subroutine hdiag_cell_values(hdiag_fld) |
There was a problem hiding this comment.
I recommend changing this to hdiag_values_cell
| ! from the start of the timestep (init_mass_diags), so are only meaningful | ||
| ! for instantaneous values. | ||
|
|
||
| subroutine hdiag_global(val, hemi, dt, budget) |
There was a problem hiding this comment.
if this is just for one hemisphere, could it be named hdiag_hemisphere?
| use ice_blocks, only: nx_block, ny_block | ||
| use ice_communicate, only: my_task, master_task | ||
| use ice_constants, only: c0, c1 | ||
| use ice_diagnostics, only: hdiag, n_hdiag, hdiag_initialized, hdiag_hemi, & |
There was a problem hiding this comment.
To reduce the amount of searching needed in ice_diagnostics.F90, it would be helpful to list the variables one-per-line with a comment on each that describes what they are . That could be done for subroutines too, or just make sure what they are doing is clearly indicated when they are called.
The subroutine names are not completely intuitive to me. E.g. 'h' means hemispheric not thickness, 'cell_values' refers to per cell, not a gridded field (values_cell would be clearer), 'global_values' is the 2 hemispheres, not 1 total global value, etc. And yes I know a lot of this is based on what's in the current code, but we didn't need to search another module to figure it out.
| ! Options for histfreq: '1','h','d','m','y','x', where x means that | ||
| ! output stream will not be used (recommended for efficiency). | ||
| ! Options for histfreq: '1','h','d','m','y','n','x', where n means | ||
| ! day histfreq_n of each month and x means that the output stream |
There was a problem hiding this comment.
Why is the n option needed? Is there not a histfreq_n for every histfreq?
|
|
||
| use ice_boundary, only: ice_HaloUpdate | ||
| use ice_calendar, only: dt, dt_dyn, ndtd, diagfreq, write_restart, istep | ||
| use ice_calendar, only: dt, dt_dyn, ndtd, write_diag, write_restart |
There was a problem hiding this comment.
diagfreq and write_diag are not used in this module
|
@anton-seaice These lines in the base code call |
|
ill mark this as draft, and look at #1164 first |
For detailed information about submitting Pull Requests (PRs) to the CICE-Consortium,
please refer to: https://github.com/CICE-Consortium/About-Us/wiki/Resource-Index#information-for-developers
PR checklist
Adds calendar units for
diagfreqand an option to write the hemispheric diagnostics (CMIP sea-ice area, extent, volume and snow mass, the other log diagnostics and the conservation diagnostics) to a netcdf file, as time averages or instantaneous values, with its own frequency and restarts. Closes Global Scalars in History Output #1074.Anton Steketee (ACCESS-NRI)
@apcraig
On Gadi (NCI) with ifx (oneapi):
diagnc,diagncr(restart) anddiagncinst1in base_suite pass, plus existing gx3 debug, alt03, isotope, tx1 and gbox128 (one hemisphere) cases with netcdf diagnostics on.print_global, and model answers and restarts are unchanged.siarean/sivolsmatch the sums of the daily mean history fields to ~1e-16.#1074 asks for hemispheric totals (area, extent, volume, ...) in netcdf output. These are useful for quick checks of runs, especially at high resolution where computing them from many large history files is slow. Following the discussion in #1074, they are built on the diagnostics already written to the log, rather than added to the history streams. CMIP7 requests the area, extent, volume and snow mass as daily means, so time averages are supported as well as instantaneous values.
diagfreq_unit'1'diagfreq(log diagnostics):'1'(timesteps, unchanged behaviour),'h','d','m','y'. Calendar units are aligned with the calendar, eg'd'is the end of each day.diag_netcdf_freq'x''x'(off),'1','h','d','m','y'.diag_netcdf_freq_n1diag_netcdf_freq_ndiag_netcdf_frequnits.diag_netcdf_avg.true.hist_avg, otherwise instantaneous values.diagfreq = 0now turns the log diagnostics off (previously a mod by zero).ice_diagnostics(hdiag_cell_values,hdiag_reduce,hdiag_derived,hdiag_global), used by both the log and the netcdf output, so the values are consistent. The log output is unchanged.ice_diagnostics_netcdf, called from the drivers withdiag_netcdf_stepafter the other diagnostics:siarean/s,siextentn/s,sivoln/s,sisnmassn/s(CMIP names and units, snow mass isrhos*vsnoas for the history fieldsisnmass), andkinetic_energy,ice_speed_rms,albedo,ice_volume_max,ice_speed_max,ice_strength_maxwith_nh/_shsuffixes.print_global(mass, energy and salt stocks, water, salt and heat fluxes as rates, isotopes and aerosols) are always in the file;print_globalonly affects the log. The changes and conservation errors are over a single timestep, so are only written for instantaneous output.<history_dir><history_file>_diag_avg.nc(or_diag_inst.nc), written serially by the master task in netcdf and pio builds. If it exists at the start of a run it is appended to, with records at or after the current time overwritten for reruns. Format, compression and precision followhistory_format,history_deflateandhistory_precision.write_histrest, the partial averages are written to their own restart file with the history restarts (<restart_dir><history_file>_diag_r.YYYY-MM-DD-SSSSS.nc), so averaging continues across restarts. Otherwise the averaging restarts at the start of each run (shown bytime_bounds).🤖 Generated with Claude Code